package IHM;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;

/**
 * 
 * @author LocoRocoBattleStein
 *
 */

public class LabelTour extends JLabel implements MouseListener{
		 
	
	private static final long serialVersionUID = 1L;
	private ImageIcon img;
	private Border borderOn;
	private Border borderOut;

	private int idTower;
	private String type;
	private boolean isClicked;
	private static int idTowerSelected;
	static boolean oneIsClicked;
	static boolean isTowerSelected;
	static boolean isEntered;

	static int money;
	static int priceTower;

	
	public static boolean isEntered() {
		return isEntered;
	}

	public static void setEntered(boolean isEntered) {
		LabelTour.isEntered = isEntered;
	}

	public boolean getIsClicked() {
		return isClicked;
	}

	public void setIsClicked(boolean val) {
		this.isClicked = val;
	}
	/**
	 * Constructor de LabelTour
	 * @param id
	 * @param type
	 */	
	     public LabelTour(int id, String type){
	             this.addMouseListener(this);
	             idTower = id;
	    		isClicked = false;
	    		this.setType(type);
	             img = new ImageIcon("medias/tour"+type+".PNG");
	             this.setIcon(img);
	             this.borderOut = BorderFactory.createLineBorder(Color.black, 1);
	             this.borderOn = BorderFactory.createLineBorder(Color.yellow, 6);
	     		 this.setBorder(borderOut);
	     		 this.setHorizontalAlignment(SwingConstants.CENTER);

	     }
	     
	     
	     /**
	      * choix de l'affichage du contour
	      * @param bool
	      */
		public void chooseBorder(boolean bool){
	    	 if(bool) this.setBorder(borderOn);
	    	 else this.setBorder(borderOut);
	     }
	     	
	        public void mouseEntered(MouseEvent event) {
	           
	        	if(money >= priceTower && money!=0){
		        	this.setBorder(borderOn);
		        	isEntered = true;
		        	setIdTowerSelected(idTower);
	        	}
	             
	        }
	 
	        
	        public void mouseExited(MouseEvent event) {
	        	
	        	if(isClicked){
	        		 this.setBorder(borderOn);
	 	        	isEntered = true;

	        	}
	        	else{
	        		 this.setBorder(borderOut);
	 	        	isEntered = false;

	        	}
	        		

	        }
	 
	        
	        public void mousePressed(MouseEvent event) {
	 
	               
	        	if ( SwingUtilities.isLeftMouseButton (event) && money >= priceTower && money!=0 ) {
	        		
		     		 this.setBorder(borderOn);
	    			setIdTowerSelected(idTower);
	    			isClicked = true;
	    			oneIsClicked = true;
	    			isTowerSelected = true;

	    		}    
	        }

			
	        public void mouseReleased(MouseEvent event) {
	                
	        }

		
		public void mouseClicked(MouseEvent e) {
			
		}



		public void setIdTour(int idTour) {
			this.idTower = idTour;
		}



		public int getIdTour() {
			return idTower;
		}

		public static void setIdTowerSelected(int idTowerSelected) {
			LabelTour.idTowerSelected = idTowerSelected;
		}

		public static int getIdTowerSelected() {
			return idTowerSelected;
		}

		public static void setOneIsClicked(boolean oneIsClicked) {
			LabelTour.oneIsClicked = oneIsClicked;
		}

		public static boolean getOneIsClicked() {
			return oneIsClicked;
		}

		public static void setIsTowerSelected(boolean isTowerSelected) {
			LabelTour.isTowerSelected = isTowerSelected;
		}

		public static boolean getIsTowerSelected() {
			return isTowerSelected;
		}
		

		public int getMoney() {
			return money;
		}

		public static void setMoney(int money) {
			LabelTour.money = money;
		}
	        
		public static int getPriceTower() {
			return priceTower;
		}

		public static void setPriceTower(int priceTower) {
			LabelTour.priceTower = priceTower;
		}

		public void setType(String type) {
			this.type = type;
		}

		public String getType() {
			return type;
		}
	        
	}
	
